package com.gistone.commis.api.restController;

import com.gistone.commis.entity.FWage;
import com.gistone.commis.mapper.FWageMapper;
import com.gistone.commis.mapper.UserMapper;
import com.gistone.commis.util.DataTablePageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by wangfan on 2017/5/20.
 */
@RestController("apiFWageController")
@RequestMapping("api/fWage")
public class FWageController {

    private static final Logger logger = LoggerFactory.getLogger(FWageController.class);


    @Autowired
    private FWageMapper fWageMapper;


    @Autowired
    private UserMapper userMapper;


    @Transactional
    @RequestMapping(method = RequestMethod.GET, value = "/pageDatatables")
    public DataTablePageUtil<FWage> pageDatatables(HttpServletRequest request, FWage fWage) {
//		HttpSession httpSession = request.getSession();
//		User user = (User) httpSession.getAttribute("userInfo");
//		logger.info("用户信息：" + user.toString());
//		int community_id = user.getCommunity().getCommunityId();
//		person.setCommunityId(community_id);



        DataTablePageUtil<FWage> dataTable = new DataTablePageUtil<>(request);

        PageHelper.startPage(dataTable.getPage_num(), 10);
        List<FWage> list = fWageMapper.selectSelective(fWage);

        PageInfo<FWage> pageInfo = new PageInfo<>(list);
        dataTable.setDraw(dataTable.getDraw());
        dataTable.setData(pageInfo.getList());
//        dataTable.setOptions(os);
        dataTable.setRecordsTotal((int) pageInfo.getTotal());
        dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
        //返回数据到页面

        return dataTable;

    }






}
